#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/module.h>

struct task_struct *task0;
static spinlock_t spinlock;
int val;

int task(void *arg) {
  printk(KERN_INFO "%s:%d\n", __func__, __LINE__);
  /* To generate panic uncomment following */
  /* panic("softlockup: hung tasks"); */

  while (!kthread_should_stop()) {
    printk(KERN_INFO "%s:%d\n", __func__, __LINE__);
    spin_lock(&spinlock);
    printk(KERN_INFO "%s:%d\n", __func__, __LINE__);
    /* busy loop in critical section */
    while (1) {
      
    }

    spin_unlock(&spinlock);
  }

  return val;
}

static int softlockup_init(void) {
  printk(KERN_INFO "%s:%d\n", __func__, __LINE__);

  val = 1;
  spin_lock_init(&spinlock);
  task0 = kthread_run(&task, (void *)val, "softlockup_thread");
  set_cpus_allowed_ptr(task0, cpumask_of(0));

  return 0;
}

static void softlockup_exit(void) {
  printk(KERN_INFO "%s:%d\n", __func__, __LINE__);
  kthread_stop(task0);
}

module_init(softlockup_init);
module_exit(softlockup_exit);
MODULE_LICENSE("GPL v2"); // 表示模块代码接受的软件许可协议
MODULE_AUTHOR("www");     // 描述模块的作者信息
MODULE_DESCRIPTION("soft lock up module"); // 对模块的简单介绍
MODULE_ALIAS("soft_lock_up_module");       // 给模块设置一个别名